﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApCableOptimizationPointCloudLayerControlBinder
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.ComponentModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

public class CApCableOptimizationPointCloudLayerControlBinder : IDisposable
{
  private bool m_isBindingInProgress;
  private readonly ICApCableEditBoxControl m_optimizationPointCloudLayerControl;
  private readonly CApFLEXCableNewAttributeViewModel m_attributeViewModel;

  public CApCableOptimizationPointCloudLayerControlBinder(
    ICApCableEditBoxControl optimizationPointCloudLayerControl,
    CApFLEXCableNewAttributeViewModel attributeViewModel)
  {
    this.m_optimizationPointCloudLayerControl = optimizationPointCloudLayerControl ?? throw new ArgumentNullException(nameof (optimizationPointCloudLayerControl));
    this.m_attributeViewModel = attributeViewModel ?? throw new ArgumentNullException(nameof (attributeViewModel));
    this.m_optimizationPointCloudLayerControl.DisplayableObject = this.m_attributeViewModel.OptimizationPointCloudLayer as ITxDisplayableObject;
    this.m_optimizationPointCloudLayerControl.ObjectChanged += new CApCableEditBoxControlEventHandler(this.OptimizationPointCloudLayerControl_ObjectChanged);
    this.m_attributeViewModel.PropertyChanged += new PropertyChangedEventHandler(this.AttributeViewModel_PropertyChanged);
    this.m_isBindingInProgress = false;
  }

  public void Dispose()
  {
    this.m_optimizationPointCloudLayerControl.ObjectChanged -= new CApCableEditBoxControlEventHandler(this.OptimizationPointCloudLayerControl_ObjectChanged);
    this.m_attributeViewModel.PropertyChanged -= new PropertyChangedEventHandler(this.AttributeViewModel_PropertyChanged);
  }

  private void AttributeViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
  {
    if (this.m_isBindingInProgress || !(e.PropertyName == "OptimizationPointCloudLayer"))
      return;
    this.m_isBindingInProgress = true;
    this.m_optimizationPointCloudLayerControl.DisplayableObject = this.m_attributeViewModel.OptimizationPointCloudLayer as ITxDisplayableObject;
    this.m_isBindingInProgress = false;
  }

  private void OptimizationPointCloudLayerControl_ObjectChanged(ICApCableEditBoxControl sender)
  {
    if (this.m_isBindingInProgress)
      return;
    this.m_isBindingInProgress = true;
    this.m_attributeViewModel.OptimizationPointCloudLayer = this.m_optimizationPointCloudLayerControl.DisplayableObject as ITxPointCloudLayer;
    this.m_isBindingInProgress = false;
  }
}
